package items
{
	import flash.utils.*;
	
	import org.flixel.*;
	
	import states.*;
	
	/**
	 * ...
	 * @author Chris Gamble
	 */
	public class Item extends Entity
	{
		protected var _size:uint;
		protected var _used:Boolean;
		protected var _duration:int;
		
		public function Item(i:uint = 0, j:uint = 0)
		{
			super(i, j);
			_used = false;
			_duration = 0;
			_size = 1;
			
			addText("Size", "", 20, 1000);
		}
		
		override public function update():void
		{
			say("Size");
		}
		
		override public function destroy():void
		{
			if (size > 1)
			{
				size--;
				_used = false;
			}
			else
			{
				kill();
				Registry.items.remove(this, true);
				super.destroy();
			}
		}
		
		public function get size():uint
		{
			return _size;
		}
		
		public function set size(newSize:uint):void
		{
			_size = newSize;
			if (_size == 1)
			{
				changeText("Size", "");
			}
			else
			{
				changeText("Size", "x" + _size.toString());
			}
		}
		
		public function onUse(p:Player):Boolean
		{
			_used = true;
			
			return true;
		}
		
		public function get used():Boolean
		{
			return _used;
		}
		
		public function get duration():int
		{
			return _duration;
		}
		
		public function logUsage():void
		{
			if (FlxG.state is GameState)
			{
				var itemName:String = getQualifiedClassName(this).slice(7);
				LoggerWrapper.logAction(Registry.actionMap[itemName], itemName);
			}
		}
		
		public function get secondsRemaining():int
		{
			if (_timer.hasExpired)
			{
				return 0;
			}
			else
			{
				return _timer.secondsRemaining + 1;
			}
		}
	}
}